﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace yfxt
{
    public partial class gl_yprkd_1 : Form
    {
        public gl_yprkd_1()
        {
            InitializeComponent();
        }

        public static string ybph;
        public static string sxrq;
        public static int yprkd_1 = 0;

        private void gl_yprkd_1_Load(object sender, EventArgs e)
        {
            dateTimePicker1.Text = DateTime.Now.ToShortDateString();
        }

        //确认按钮
        private void button1_Click(object sender, EventArgs e)
        {
            yprkd_1 = 0;
            if (dateTimePicker1.Value>=DateTime.Now)
            {

                if (!(textBox1.Text == "" || textBox2.Text == "" || dateTimePicker1.Value.ToShortDateString() == DateTime.Now.ToShortDateString()))
                {
                    ybph = textBox2.Text.ToString();
                    sxrq = dateTimePicker1.Value.ToString("yyyy-MM-dd").Replace('-', '.');
                    this.Close();
                }
                else
                {
                    MessageBox.Show("不能留空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("失效日期写错了！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        //取消按钮
        private void button2_Click(object sender, EventArgs e)
        {
            yprkd_1 = 1;
            this.Close();
        }

        //控制textBox只能输入正数
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //键盘"0"和退格键可以按
            if (e.KeyChar != '\b' && e.KeyChar != '0')
            {
                e.Handled = true;
            }
            //键盘"."可以按            
            if (e.KeyChar == (char)46)
            {
                if (!(textBox1.Text == "" || textBox1.Text.ToString().Contains(".")))
                {
                    e.Handled = false;
                }
            }
            //键盘"1"到"9"可以按            
            if (e.KeyChar >= '1' && e.KeyChar <= '9')
            {
                if (!(textBox1.Text.ToString().Length == 1 && textBox1.Text == "0"))
                {
                    e.Handled = false;
                }  
            }      
        }
    }
}
